package com.danielagarza.app.servicios;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class LeerJSON {

	private static String readJSON(InputStream in) {
		String line = "";
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new InputStreamReader(in));
			line = reader.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return line;
	}
	
	public static String leerJSON(String ruta){
		String json ="";
		 try {
			  URL url = new URL(ruta);
			  HttpURLConnection con = (HttpURLConnection) url.openConnection();
			   json = readJSON(con.getInputStream()).toString();
			  } catch (Exception e) {
				  System.out.println(">>>"+e.getMessage());
			}
		 return json;
	}
}
